package com.example.dbRouting.db;

import com.example.dbRouting.DbContextHolder;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import java.util.logging.Logger;

/**
 * @Description: TODO(SPring 的动态数据源的实现)
 * @author wangkai
 * @date 2018年5月31日
 *
 */
public class DynamicDataSource extends AbstractRoutingDataSource {
	public static final Logger logger = Logger.getLogger(DynamicDataSource.class.toString());

	@Override
	@SuppressWarnings("static-access")
	protected Object determineCurrentLookupKey() {
		String dbkey = DbContextHolder.init().getDbKey();
		logger.info("当前操作对应数据源：" + dbkey);
		return dbkey;// 获取当前数据源
	}


}